var o, e = require, t = module, n = exports, i = this && this.__extends || (o = function(e, t) {
    return (o = Object.setPrototypeOf || {
        __proto__: []
    } instanceof Array && function(e, t) {
        e.__proto__ = t;
    } || function(e, t) {
        for (var o in t) t.hasOwnProperty(o) && (e[o] = t[o]);
    })(e, t);
}, function(e, t) {
    function c() {
        this.constructor = e;
    }
    o(e, t), e.prototype = null === t ? Object.create(t) : (c.prototype = t.prototype, 
    new c());
}), a = this && this.__decorate || function(e, t, o, c) {
    var i, s = arguments.length, n = s < 3 ? t : null === c ? c = Object.getOwnPropertyDescriptor(t, o) : c;
    if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) n = Reflect.decorate(e, t, o, c); else for (var r = e.length - 1; 0 <= r; r--) (i = e[r]) && (n = (s < 3 ? i(n) : 3 < s ? i(t, o, n) : i(t, o)) || n);
    return 3 < s && n && Object.defineProperty(t, o, n), n;
};

Object.defineProperty(n, "__esModule", {
    value: !0
});

var r = e("ActionCommon"), s = cc._decorator, c = s.ccclass, l = s.property, d = function(t) {
    function e() {
        var e = null !== t && t.apply(this, arguments) || this;
        return e.vec = cc.Vec2.ZERO, e.type = r.default.ActionType.MOVEBY, e.life = r.default.ActionLife.START, 
        e.scope = r.default.ActionScope.SELF, e.delay = 0, e.speed = 800, e.pos = null, 
        e.isStart = !1, e;
    }
    var s;
    return i(e, t), (s = e).prototype.onLoad = function() {
        var c = this;
        this.pos = this.node.getPosition(), this.scope == r.default.ActionScope.CHILDREN && this.node.children.forEach(function(e, t) {
            var o = e.addComponent(s);
            o.pos = e.getPosition(), o.type = c.type, o.life = c.life, o.vec = c.vec, o.speed = c.speed, 
            o.delay = t * c.delay;
        }), this.life == r.default.ActionLife.LOAD && (this.isStart = !0);
    }, e.prototype.onEnable = function() {
        this.scope == r.default.ActionScope.SELF && this.isStart && this.doAction();
    }, e.prototype.start = function() {
        this.life == r.default.ActionLife.START && (this.isStart = !0);
    }, e.prototype.doAction = function() {
        switch (this.type) {
          case r.default.ActionType.MOVEBY:
            this.moveByAction();
            break;

          case r.default.ActionType.REPEATMOVEBY:
            this.repeatMoveByAction();
            break;

          case r.default.ActionType.SCALETO:
            this.scaleToAction();
            break;

          case r.default.ActionType.REPEATFOREVERMOVEBY:
            this.repeatForeverMoveByAction();
        }
    }, e.prototype.moveByAction = function() {
        cc.Tween.stopAllByTarget(this.node), this.node.setPosition(this.pos.sub(this.vec)), 
        (0 < this.delay ? cc.tween(this.node).delay(this.delay) : cc.tween(this.node)).by(this.vec.mag() / this.speed, {
            position: cc.v3(this.vec)
        }, {
            easing: "quadOut"
        }).start();
    }, e.prototype.repeatMoveByAction = function() {
        cc.Tween.stopAllByTarget(this.node), this.node.setPosition(this.pos.sub(this.vec));
        var e = this.vec.mag() / this.speed;
        (0 < this.delay ? cc.tween(this.node).then(cc.sequence(cc.delayTime(this.delay), cc.moveBy(e, this.vec), cc.moveBy(.3 * e, this.vec.mul(-.15)), cc.moveBy(.3 * e, this.vec.mul(.15)), cc.moveBy(.15 * e, this.vec.mul(-.05)), cc.moveBy(.15 * e, this.vec.mul(.05))).easing(cc.easeOut(3))) : cc.tween(this.node).then(cc.sequence(cc.moveBy(e, this.vec), cc.moveBy(.3 * e, this.vec.mul(-.15)), cc.moveBy(.3 * e, this.vec.mul(.15)), cc.moveBy(.15 * e, this.vec.mul(-.05)), cc.moveBy(.15 * e, this.vec.mul(.05))).easing(cc.easeOut(3)))).start();
    }, e.prototype.repeatForeverMoveByAction = function() {
        var e = this.vec.mag() / this.speed;
        cc.tween(this.node).repeatForever(cc.tween().by(e, {
            position: this.vec
        }).by(e, {
            position: this.vec.neg()
        })).start();
    }, e.prototype.scaleToAction = function() {
        cc.Tween.stopAllByTarget(this.node);
        var e = 400 / this.speed;
        (0 < this.delay ? cc.tween(this.node).delay(this.delay) : cc.tween(this.node)).to(e, {
            scale: 1
        }).start();
    }, a([ l(cc.Vec2) ], e.prototype, "vec", void 0), a([ l({
        type: r.default.ActionType
    }) ], e.prototype, "type", void 0), a([ l({
        type: r.default.ActionLife
    }) ], e.prototype, "life", void 0), a([ l({
        type: r.default.ActionScope
    }) ], e.prototype, "scope", void 0), a([ l ], e.prototype, "delay", void 0), a([ l ], e.prototype, "speed", void 0), 
    s = a([ c ], e);
}(cc.Component);

n.default = d;